/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} x
 * @return {ListNode}
 */
var partition = function(head, x) {
    if(!head)return head
     let newdummy=new ListNode(0)
     let curr=new ListNode(0,head)
     let p1 =newdummy
     let newHead=head
     while(newHead.val>=x)  
     {
        newHead=newHead.next
        if(newHead&&newHead.val<x)
        {
            break
        }
        if(newHead===null)
        {
            return head
        }
     }
   
     while(curr.next!=null)
     {
        if(curr.next.val>=x)
        {
            p1.next=curr.next
            p1=p1.next
            curr.next=curr.next.next
        }
        else{
               curr=curr.next
        }
        
     }
     p1.next=null
     curr.next=newdummy.next
     return newHead
     

};